package org.Modulo2;

import org.afree.chart.AFreeChart;
import org.afree.chart.ChartFactory;
import org.afree.chart.plot.PiePlot;
import org.afree.chart.title.TextTitle;
import org.afree.data.general.DefaultPieDataset;
import org.afree.data.general.PieDataset;
import org.afree.graphics.geom.Font;

import android.content.Context;
import android.graphics.Typeface;

public class GraficoQueso extends DemoView{

	private final DefaultPieDataset dataset;
	
	
	public GraficoQueso(Context context) {
		super(context);
		
		dataset = null;
        //final AFreeChart chart = createChart(dataset);


      //  setChart(chart);
	}
	
	public static String createDataset(char c, int n) {
        String dataset =tipoGasto(c,n);
        return dataset;
        
    }
	
	private static String tipoGasto(char c, int n){
		String ret=" ";
		switch (c){
		case 'L':
			if(n>860) ret="Luz "+n;
			break;
		case 'A':
			if(n>37) ret="Agua "+n;
			
			break;
		case 'G':
			if(37<=n&&n<=200) ret="Gas "+n;
			break;
		case 'T':
			if(9<=n&&n<=60) ret="Telefono "+n;
			break;
		case 'C':
			if(10<=n&&n<=50) ret="Compras "+n;
			break;
		case 'I':
			if(600<=n&&n<=3000) ret="Ingresos "+n;
			break;
		case 'P':
			if(10<=n&&n<=100) ret="Prestamo "+n;
			break;
		}
		return ret;
	}
	
	public final PieDataset getDataset(){
		return dataset;
	}
	
	public final void cambiaValor(String tipo, double value){
		dataset.setValue(tipo, Double.valueOf(value));
	}

	/*private static AFreeChart createChart(PieDataset dataset) {

        AFreeChart chart = ChartFactory.createPieChart("Ancient", // chart title
                dataset, // data
                true, // include legend
                true,
                false);
        TextTitle title = chart.getTitle();
        title.setToolTipText("A title tooltip!");
               

        PiePlot plot = (PiePlot) chart.getPlot();
        
        
        /*List<Comparable> l = dataset.getKeys();
        plot.setSectionPaintType(l.get(0), new SolidColor(ChartColor.VERY_LIGHT_BLUE));
        plot.setLabelFont(new Font("SansSerif", Typeface.NORMAL, 12));
        plot.setNoDataMessage("No data available");
        plot.setCircular(true);
        plot.setLabelGap(0.02);
        return chart;

    }*/
	
	public static int cambiaValor(String tipo, String valor){
		int ret=0;
		int tipo_valor=getTipo(tipo);
		switch(tipo_valor){
		case 0:
			ret=Integer.parseInt(valor);
			break;
		case 1:
			ret=(int) Double.parseDouble(valor);
		break;
		case 2:
			ret=(int) Float.parseFloat(valor);
			break;
		}
		
		return ret;
		
	}
	
	public static int getTipo(String tipo){
		int tipo_valor=0;
		if(tipo.equalsIgnoreCase("Double")){
			tipo_valor=1;
		}
		else{
			if(tipo.equalsIgnoreCase("String")){
				tipo_valor=0;
			}
			else {
				if(tipo.equalsIgnoreCase("Float")){
					tipo_valor=2;
				}
				else{
					if(tipo.equalsIgnoreCase("Integer")){
						tipo_valor=0;
					}
				}
			}
		}
		return tipo_valor;
	}

}
